#ifndef DISPLAYMODES_H
#define DISPLAYMODES_H

#include "CommonTypes.h"
#include "VideoSettings.h"

namespace Cvekas {

/// Display mode
class DisplayMode
{
public:

	/// Constructor
	/// \param mode D3DDISPLAYMODE structure
	DisplayMode(D3DDISPLAYMODE& mode);

	/// Copy constructor
	DisplayMode(const DisplayMode& display_mode);

	/// Destructor
	~DisplayMode();

	/// Returns width of screen in pixels
	uint getWidth();
	/// Returns height of screen in pixels
	uint getHeight();
	/// Returns monitor refresh rate
	uint getRefreshRate();
	/// Returns device format
	D3DFORMAT getFormat();
	/// Returns original D3DDISPLAYMODE used to construct this DisplayMode
	D3DDISPLAYMODE getD3DDisplayMode();
	/// Returns description of display mode in printable format
	std::string getDescription();

	/// Sort operator
	bool operator<(const DisplayMode& d) const;
	/// Equality operator
	bool operator==(const DisplayMode& d) const;

private:
	D3DDISPLAYMODE mode;
};

/// Collection of all supported display modes
class DisplayModes : public boost::noncopyable
{
public:
	/// Gets amount of supported display modes
	uint getModeCount();
	/// Gets specific display mode
	/// \param i Mode index, must be between zero and number returned by getModeCount() 
	DisplayMode& getMode(uint i);
	/// Returns index of real current display mode (desktop mode if not fullscreen)
	uint getCurrentMode();
	/// Returns index of current application mode
	uint getCurrentAppMode(VideoSettings& settings);
	/// Returns index of desktop display mode
	uint getDesktopMode();
	/// Finds mode index, ~0 if not supported
	uint findMode(uint width, uint height, uint refresh);
	
	/// Modifies VideoSettings to correspond to a new display mode
	/// \param settings VideoSettings instance to modify
	/// \param i Mode index, must be between zero and number returned by getModeCount() 
	void setMode(VideoSettings& settings, uint i);

private:
	DisplayModes(D3DPtr d3d);
	std::vector<DisplayMode> modes;
	uint mode_count;
	uint desktop_mode;

	D3DPtr d3d;

	friend class VideoDevice;
};

typedef boost::shared_ptr<DisplayModes> DisplayModesPtr;

}

#endif